home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 291_01 / jjbshow5.c < prev    next >
Encoding:
Text File  |  1989-06-26  |  11.9 KB  |  252 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *                           JJBSHOW5.C                                   *
  4.  *                                                                        *
  5.  *   Copyright (c) 1988, 1989, JJB. All rights reserved.                  *
  6.  *                                                                        *
  7.  *   This example shows you how to use the 'enter' functions so you can   *
  8.  *   input entire screens of data.                                        *
  9.  *                                                                        *
  10.  *   Turbo C is a trademark of Borland International, Inc.                *
  11.  *   Quick C is a trademark of Microsoft Corp.                            *
  12.  *   JJB, 9236 church Rd suite 1082, Dallas, Tx 75231 (214) 341-1635      *
  13.  **************************************************************************/
  14.  
  15.  
  16. /***************************************************************************
  17.  * For Turbo C programmers only:                                           *
  18.  *   To run this program from DOS:                                         *
  19.  *                                                                         *
  20.  *         Enter 'TC JJBSHOW5'    ( to load this file with Turbo C)        *
  21.  *         Press 'CTRL F9'        ( to compile and begin executing)        *
  22.  *                                                                         *
  23.  ***************************************************************************/
  24.  
  25. /***************************************************************************
  26.  * for Quick C programmers only:                                           *
  27.  *   To run this program, from DOS:                                        *
  28.  *                                                                         *
  29.  *         Enter 'JJBQCS5'    ( to load this file with JJB.QLB)            *
  30.  *         Press 'F5'         ( to compile and begin executing)            *
  31.  *                                                                         *
  32.  *   To make the .exe file JJBSHOW5.EXE, from DOS enter:                   *
  33.  *         QCL  /c  /AM  JJBSHOW5.C                                        *
  34.  *         LINK  JJBSHOW5 + JJBQC + JJBQCINP + JJBQCDOL,,, C:LIB\,         *
  35.  *                                                                         *
  36.  ***************************************************************************/
  37.  
  38. /***************************************************************************
  39.  *                                                                         *
  40.  * for both TURBO C and QUICK C programmers:                               *
  41.  *                                                                         *
  42.  * Not all options have been assigned functions. The options unassigned    *
  43.  * execute the JJB copyright function.                                     *
  44.  *                                                                         *
  45.  * As JJB executes (runs) a program, the following keys can be pressed:    *
  46.  *                                                                         *
  47.  *    ALT X     to exit.                                                   *
  48.  *    F1        to display a help screen.                                  *
  49.  *    F2-F9     to instantly select another option.                        *
  50.  *    ALT       to select a group of options.                              *
  51.  *    ALT       and a letter to select a specific group.                   *
  52.  *    ESC       means nevermind.                                           *
  53.  *       ->        to select the group to the right.                       *
  54.  *       <-        to select the group to the left.                        *
  55.  *       UPARROW   to highlight the option above.                          *
  56.  *       DOWNARROW to highlight the option below.                          *
  57.  *       RETURN    to select the option highlighted.                       *
  58.  *       A LETTER  to select a specific option.                            *
  59.  *       ALT and a letter to select a different group.                     *
  60.  *       ESC       return exactly where you were in the function           *
  61.  *                      currently being executed.                          *
  62.  *                                                                         *
  63.  * If another option is selected, JJB will execute:                        *
  64.  *                                                                         *
  65.  *         the leave function for the current option.                      *
  66.  *         the leave function for the current group.                       *
  67.  *         the initalization function for the selected group.              *
  68.  *         the initalization function for the selected option.             *
  69.  *         and option function.                                            *
  70.  *                                                                         *
  71.  ***************************************************************************/
  72.  
  73. /* see JJB-READ.DOC for an additional explanation of the functions below.  */
  74.  
  75. #include <jjbkbd.h>
  76. #include <jjbset.h>
  77.  
  78. main() {
  79.  
  80.   jjb_initalize();        /* initalize the jjb functions             */
  81.   jjb_setup();            /* set up your options and assign functions*/
  82.   jjb_start();            /* start executing the default option      */
  83.     }
  84.  
  85.  
  86. /****************************************************************************
  87.  *                                                                          *
  88.  *                            SAMPLE HELP FUNCTION                          *
  89.  *                                                                          *
  90.  ****************************************************************************/
  91.  
  92. int scr1_arry[2000];
  93.  
  94. sample_help() {
  95.      vsave_scr(&scr1_arry);  /* save the screen   */
  96.      set_color(RED ONBLUE);
  97.      vfw(6,11,64,14);        /* 'vf' a window     */
  98.  
  99.      vloc(8,14);      /* position for video fast functions */
  100.  
  101.     /* 'vfsdo(' videos fast a string and then does a carriage ret.
  102.        '2,14' sets up all subsequent to come down two and over 14. */
  103.  
  104.      vfsdo("F1 is reserved for help.",2,14);
  105.  
  106.      vfsdo("You can set up a function and call it by using the F1 key.",SAME);
  107.      vfsdo("JJB will use whatever function you assign in jjb_setup().",SAME);
  108.      vfsdo("In this example, jjb_setup assigns sample_help() as follows:",SAME);
  109.      vfsdo("      'help(sample_help);'",3,14);
  110.      vfsc( pak() );     /* video fast 'Press any key'and put cursor after  */
  111.      getch();           /* getch() is ok here.                             */
  112.      normal();
  113.      vrest_scr(&scr1_arry);    /* restore the screen                              */
  114.      }
  115. /****************************************************************************
  116.  *                                                                          *
  117.  *                            SAMPLE FUNCTION                               *
  118.  *                                                                          *
  119.  ****************************************************************************/
  120.  
  121.  
  122. update_cust()  {  int x;  unsigned long lfrom, lto;
  123.   char buffer[256];    /*  customer I/O buffer    */
  124.  
  125.   /*   define the define pointers   */
  126.   char *name, *street, *city, *phone1, *phone2, *phone3,
  127.        *comment, *mo, *day, *year, *check , *amt,
  128.        *pak = "  ";  /* for press any key   */
  129.  
  130.   /*   define the data lengths.        */
  131.   /*   if you change any data length, the buffer pointers below
  132.        will automatically be adjusted for the new address        */
  133.  
  134.   int lname    = 44,
  135.       lstreet  = 30,
  136.       lcity    = 30,
  137.       lphone1  =  3,
  138.       lphone2  =  3,
  139.       lphone3  =  4,
  140.       lcomment =  30,
  141.       lmo      = 2,
  142.       lday     = 2,
  143.       lyear    = 2,
  144.       lcheck   = 6,
  145.       lamt     = 14;
  146.       x=1;
  147.  
  148.   /* store buffer address in the character pointers     */
  149.       name    = &buffer[x];   x += lname    +1;
  150.       street  = &buffer[x];   x += lstreet  +1;
  151.       city    = &buffer[x];   x += lcity    +1;
  152.       phone1  = &buffer[x];   x += lphone1  +1;
  153.       phone2  = &buffer[x];   x += lphone2  +1;
  154.       phone3  = &buffer[x];   x += lphone3  +1;
  155.       comment = &buffer[x];   x += lcomment +1;
  156.       mo      = &buffer[x];   x += lmo      +1;
  157.       day     = &buffer[x];   x += lday     +1;
  158.       year    = &buffer[x];   x += lyear    +1;
  159.       check   = &buffer[x];   x += lcheck   +1;
  160.       amt     = &buffer[x];   x += lamt     +1;
  161.  
  162.  
  163.   /*a  zero data buffer  */
  164.   for (x=0; x<256; ++x) buffer[x] = '\0';
  165.  
  166. /* Normally you would read the data file, but since we don't have a data
  167.    file in this example, we need to fill the data buffer as follows:  */
  168.  
  169.   name    = "John Thomas Wellington";
  170.   street  = "1527 South Meadow Road";
  171.   city    = "Dallas, TX    75247";
  172.   phone1  = "214";  phone2 = "357";  phone3 = "8934";
  173.   comment = "Place any comment here";
  174.   mo      = "11";
  175.   day     = "24";
  176.   year    = "88";
  177.   check   = "34512";
  178.  
  179.   amt     = "";
  180.   vloc(15,22); vfs("(   )    -");    /*  for phone number  */
  181.   vloc(19,22); vfs("  -  -  ");      /*  for date  */
  182.  
  183.  
  184.    vloc(4,3); vfs("Note: ");
  185. vfsdo("At any time while entering, you can press: ALT to change options.",1,9);
  186.    /* Notice 'SAME' on next line does 1 down 9 over.                    */
  187.    vfsdo("UP-DOWN ARROWS to backup, '*' to remove data.",SAME);
  188.    vfsdo("Plus any assigned function keys F1-F9, or ALT X to exit.",SAME);
  189.    vfsdo("SPACE BAR is same as RETURN if first character entered.",SAME);
  190.  
  191. /*  BEGIN....AGAIN  is a continuous while loop                          */
  192. /*  example: eptr(4) will be true only if the entry pointer equals 4    */
  193. /*  Each enter( increments the entry pointer by 1                       */
  194. /*  In addition to entering, JJB also displays the data from the buffer */
  195. /*  Since the buffer is updated directly, the only thing left for the   */
  196. /*    programmer to do is to read & write the record to the disk file.  */
  197. /*  The first time thru the enter( will just display the screen.        */
  198. /*  until it starts with (x)                                            */
  199.  
  200.   eptr_reset();    /* set eptr (enter pointer) to 1        */
  201.  
  202.  
  203.   lfrom = 100;            /* see enter_lnum(  below       */
  204.   lto = 999998;
  205.  
  206. BEGIN
  207.  
  208.   if (eptr(1))  enter(9,9 ,   "Enter name: ",name,   lname,ATEND);
  209.   if (eptr(2))  enter(11,12,     " street: ",street, lstreet,ATEND);
  210.   if (eptr(3))  enter(13,12,     "   city: ",city,   lcity,ATEND);
  211.   if (eptr(4))  enter_num(15,12, "  phone: ",phone1, lphone1,100,999,15,23);
  212.   if (eptr(5))  enter_num(15,12, "  phone: ",phone2, lphone2,100,999,15,28);
  213.   if (eptr(6))  enter_num(15,12, "  phone: ",phone3, lphone3,1000,9999,15,32);
  214.   if (eptr(7))  enter (17,12,    "comment: ",comment, lcomment,17,22);
  215.   if (eptr(8))  enter_num (19,12,"   date: ",mo,  lmo,  1,12,19,22);
  216.   if (eptr(9))  enter_num (19,12,"   date: ",day, lday, 1,31,19,25);
  217.   if (eptr(10)) enter_num (19,12,"   date: ",year,lyear,0,99,19,28);
  218.   if (eptr(11)) enter_lnum (21,12," check#: ",check,lcheck,lfrom,lto,21,23);
  219.   if (eptr(12))  enter_dollar(23,12," amount:",amt, 23,22);
  220.   if (eptr(13)) {enter(23,50 ,"Press any key ",pak, 1,ATEND);
  221.        vloc(23,50); vspaces(22);}
  222.  
  223.   eptr_start_with(1);   /* turn off displaying and start entering     */
  224.  
  225. AGAIN
  226.  
  227. }
  228.  
  229.  
  230. jjb_setup() {
  231.   group("Update");
  232.       option("Update customer file");
  233.           funct(update_cust);
  234.       option("Type the");
  235.       option("Description to");
  236.       option("Your options here.",DRAWLINE);
  237.       option("Each group can");
  238.       option("have as many ");
  239.       option("Options as you need.");
  240.  
  241.   group("Other");
  242.       option("These options have no");
  243.       option("functions assigned to them.");
  244.  
  245.        help(sample_help);
  246.  
  247.    }
  248.  
  249.  
  250.  
  251.  
  252.